/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import React from 'react';
import {View, Text, TouchableOpacity, StyleSheet, Dimensions} from 'react-native';
import {useNavigation, useRoute} from '@react-navigation/native';
import AvoidContainer from '../../../components/AvoidContainer/AvoidContainer';

const Page = (): JSX.Element => {
  const navigation = useNavigation();
  const route = useRoute();
  const {width} = Dimensions.get('window');
  const {value, format, position} = route.params || {};

  const posText = position
    ? `topLeft(${position.topLeftCorner?.x}, ${position.topLeftCorner?.y})\n` +
      `topRight(${position.topRightCorner?.x}, ${position.topRightCorner?.y})\n` +
      `bottomLeft(${position.bottomLeftCorner?.x}, ${position.bottomLeftCorner?.y})\n` +
      `bottomRight(${position.bottomRightCorner?.x}, ${position.bottomRightCorner?.y})`
    : '未知';

  return (
    <AvoidContainer>
      <View>
        <View style={styles.container}>
          <View style={[styles.header, {width}]}>
            <TouchableOpacity style={styles.backBtn} onPress={(): void => navigation.goBack()}>
              <Text style={styles.backText}>{'< 返回'}</Text>
            </TouchableOpacity>
            <Text style={styles.headerTitle}>码值</Text>
          </View>
          <View style={styles.content}>
            <Text style={styles.label}>类型</Text>
            <Text style={styles.value}>{format || 'unknown'}</Text>
            <Text style={[styles.label, {marginTop: 16}]}>码值</Text>
            <Text style={styles.value}>{value || ''}</Text>
            <Text style={[styles.label, {marginTop: 16}]}>码位置信息</Text>
            <Text style={styles.value}>{posText}</Text>
          </View>
        </View>
      </View>
    </AvoidContainer>
  );
};

const styles = StyleSheet.create({
  container: {flex: 1, backgroundColor: '#000'},
  header: {
    height: 56,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    paddingHorizontal: 16,
    borderBottomWidth: 1,
    borderColor: 'rgba(255,255,255,0.15)',
  },
  backBtn: {paddingVertical: 8, paddingHorizontal: 8},
  backText: {color: '#000000ff', fontSize: 14},
  headerTitle: {color: '#000000ff', fontSize: 16},
  content: {padding: 16},
  label: {color: '#9aa0a6', fontSize: 12},
  value: {color: '#000000ff', fontSize: 14, marginTop: 4},
});

export default Page;
